/*
 * @lc app=leetcode.cn id=409 lang=cpp
 *
 * [409] 最长回文串
 */

#include <limits.h>

#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

// @lc code=start
class Solution {
   public:
    int longestPalindrome(string s) {
        int flag = 0;
        int result = 0;
        vector<int> s_count(30, 0);
        vector<int> S_count(30, 0);

        for (char c : s) {
            if ('a' <= c && c <= 'z') {
                s_count[c - 'a']++;
            }
            if ('A' <= c && c <= 'Z') {
                S_count[c - 'A']++;
            }
        }

        for (int count : s_count) {
            result += (count / 2) * 2;
            if (count % 2 == 1) {
                flag = 1;
            }
        }
        for (int count : S_count) {
            result += (count / 2) * 2;
            if (count % 2 == 1) {
                flag = 1;
            }
        }

        return (result + flag);
    }
};
// @lc code=end
